﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;

namespace _1065093_1065130_1065120_DoAn
{
    public partial class QuyDinhDiemThanThiet : UserControl
    {
        public QuyDinhDiemThanThiet()
        {
            InitializeComponent();
        }

        public void LoadTS()
        {
            THAMSOBUS tsBUS = new THAMSOBUS();
            DataTable dt = new DataTable();
            dt = tsBUS.LoadThamSo();
            dgvthamso.DataSource = dt;
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            lbmats.Text = dgvthamso.CurrentRow.Cells[0].Value.ToString();
            lbtents.Text = dgvthamso.CurrentRow.Cells[1].Value.ToString();
            txtgiatri.Text = dgvthamso.CurrentRow.Cells[2].Value.ToString();
            txtkieu.Text = dgvthamso.CurrentRow.Cells[3].Value.ToString();
        }

        private void txtgiatri_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void QuyDinhDiemThanThiet_Load(object sender, EventArgs e)
        {
            LoadTS();
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            DialogResult result = MessageBox.Show("Bạn có muốn sửa?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                try
                {
                    int ma = Convert.ToInt32(lbmats.Text);
                    int giatri = Convert.ToInt32(txtgiatri.Text);
                    string kieu = txtkieu.Text;

                    THAMSOBUS tsBus = new THAMSOBUS();
                    tsBus.SuaThamSo(ma,giatri,kieu);
                    LoadTS();
                    MessageBox.Show("Thành công");
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
        }
    }
}
